<template>
  <div>
    <el-table
    :data="tableData"
    :stripe="true"
    style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="文件编号">
              <span>{{ props.row.file_id }}</span>
            </el-form-item>
            <el-form-item label="文件名">
              <span>{{ props.row.name }}</span>
            </el-form-item>
            <el-form-item label="提交日期">
              <span>{{ props.row.sub_date}}</span>
            </el-form-item>
            <el-form-item label="提交时间">
              <span>{{ props.row.sub_time }}</span>
            </el-form-item>
            <el-form-item label="批改老师">
              <span>{{ props.row.teacher_name === null?'未批改': props.row.teacher_name}}</span>
            </el-form-item>
            <el-form-item label="批改日期">
              <span>{{ props.row.check_date === null?'未批改': props.row.check_date }}</span>
            </el-form-item>
            <el-form-item label="批改时间">
              <span>{{ props.row.check_time === null?'未批改':props.row.check_time }}</span>
            </el-form-item>
            <el-form-item label="评论">
              <span>{{ props.row.comments ===null?'未批改': props.row.comments }}</span>
            </el-form-item>
            <el-form-item label="状态">
              <span>{{ rate[props.row.status].value }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
        label="文件编号"
        >
        <template slot-scope="scope">
          <span>{{ scope.row.file_id }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="文件名"
        >
        <template slot-scope="scope">
          <span >{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="提交日期"
       >
        <template slot-scope="scope">
          <span >{{ scope.row.sub_date}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="提交时间"
        >
        <template slot-scope="scope">
          <span >{{ scope.row.sub_time }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="批改老师"
        >
        <template slot-scope="scope">
          <span >{{ scope.row.teacher_name === null?'未批改': scope.row.teacher_name}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="批改日期"
        >
        <template slot-scope="scope">
          <span >{{ scope.row.check_date === null?'未批改': scope.row.check_date}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="批改时间"
       >
        <template slot-scope="scope">
          <span >{{ scope.row.check_time === null?'未批改':scope.row.check_time}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="评论"
        show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span >{{ scope.row.comments ===null?'未批改': scope.row.comments}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
        >
        <template slot-scope="scope">
          <el-tag
          :type=tag[scope.row.status]
          disable-transitions>{{rate[scope.row.status].value}}</el-tag>
        </template>
      </el-table-column>

      <el-table-column 
      label="操作"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">撤销</el-button>
        </template>
      </el-table-column>
    </el-table>
    
   
  </div>
  
</template>

<script>
import { showFile, deleteFile } from '@/api/user'

export default {
  
  data() {
    return {
      tableData: [],
      file_infor: {},
      rate: [],
      tag:['info','success','success','warning','','danger']
    }
  },
  created: function() {
    showFile(this.$store.getters.token).then(response => {
      this.tableData = response.data.files
      this.rate = response.data.rate
    })
  },
  methods: {
    handleDelete(index, row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if(this.$store.getters.leader!==0)
        {
          deleteFile({ 'file_id': this.tableData[index].file_id }).then(response => {
            this.$message({
              message: response.message,
              type: response.data.message
            })
            if(response.code===20000){
              this.$delete(this.tableData, index)
            }
          })
        }else{
          this.$message({
            message: '只有组长可以撤销文件',
            type: 'error'
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
    
  }

  
}

</script>


<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
